package com.javabi.htmlbuilder.css.margin;

import com.javabi.htmlbuilder.css.CSSBuilder;
import com.javabi.htmlbuilder.css.CSSDeclaration;
import com.javabi.htmlbuilder.css.CSSPropertyName;
import com.javabi.htmlbuilder.css.unit.CSSUnit;

/**
 * A Margin.
 */
public class Margin implements CSSDeclaration {

	/** The unit. */
	private final CSSUnit unit;
	/** The top margin. */
	private final Number top;
	/** The right margin. */
	private final Number right;
	/** The bottom margin. */
	private final Number bottom;
	/** The left margin. */
	private final Number left;

	/**
	 * Creates a new declaration.
	 * @param unit the margin unit.
	 * @param top the margin top.
	 * @param right the margin right.
	 * @param bottom the margin bottom.
	 * @param left the margin left.
	 */
	public Margin(CSSUnit unit, Number top, Number right, Number bottom, Number left) {
		if (unit == null || top == null || right == null || bottom == null || left == null) {
			throw new NullPointerException();
		}
		this.unit = unit;
		this.top = top;
		this.right = right;
		this.bottom = bottom;
		this.left = left;
	}

	/**
	 * Returns the property.
	 * @return the property.
	 */
	public CSSPropertyName getPropertyName() {
		return CSSPropertyName.MARGIN;
	}

	/**
	 * Append this to the given css builder.
	 * @param css the css builder.
	 * @return the css builder.
	 */
	public CSSBuilder appendTo(CSSBuilder css) {
		css.property(getPropertyName());
		css.number(top, unit);
		css.space();
		css.number(right, unit);
		css.space();
		css.number(bottom, unit);
		css.space();
		css.number(left, unit);
		return css;
	}

}
